<template>
	<view class="welcome">
		<image v-if="postUrl" style="width: 100%;height: 100%" :src="postUrl" @load="loadingSuccess"></image>
<!--    剩余跳转提示-->
    <view
        v-if="num > -1"
        @click="clear"
        class="num-box">跳过{{ num }}</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex'
	export default {
		data() {
			return {
        postUrl: '',
        num: -1,
        interval: null
			}
		},
    computed: {
      ...mapGetters(['userInfo', 'role']),
    },
		methods: {
      loadingSuccess() {
        this.num = 5
        this.interval = setInterval(() => {
          this.num--
          if (this.num === -1) {
            this.clear()
          }
        }, 1000)
      },
      clear() {
        clearInterval(this.interval)
        this.interval = null
        if (this.userInfo.id) {
          console.log(this.role)
          if (this.role === 'staff') {
            uni.reLaunch({
              url: '/pages/index/index'
            })
          } else if (this.role === 'user') {
            uni.reLaunch({
              url: '/pages/task/todo'
            })
          } else {
            uni.reLaunch({
              url: '/pages/user/login'
            })
          }
        } else {
          uni.reLaunch({
            url: '/pages/user/login'
          })
        }
      }
		},
    onReady() {
      this.$api.bannerList(3).then(res => {
        if (res.length) {
          this.postUrl = res[0].image
        }else {
          this.clear()
        }
      })
    }
	}
</script>

<style lang="scss">
.welcome {
  width: 100%;
  height: 100vh;
  position: relative;
  .num-box {
    position: absolute;
    right: 30rpx;
    top: 200rpx;
    padding: 8rpx 12rpx;
    border-radius: 16rpx;
    font-size: 28rpx;
    color: #ffffff;
    background-color: rgba(0, 0, 0, 0.5);
  }
}
</style>
